from flask import render_template, session

from models import db
from models.index import User, Commodity
from . import index_blu


# 主页
@index_blu.route("/")
def index():
    user_id = session.get("user_id")
    print("--------------------------", user_id)

    user = db.session.query(User).filter(User.user_id == user_id).first()

    commodity = db.session.query(Commodity).filter().all()
    print("--------------------------", commodity)

    return render_template('index.html', user=user, commodity=commodity)


# 登录
@index_blu.route("/login.html")
def login():
    return render_template("login.html")


# 注册
@index_blu.route("/signup.html")
def signup():
    return render_template("signup.html")


@index_blu.route("/about-us.html")
def about():
    user_id = session.get("user_id")
    user = db.session.query(User).filter(User.user_id == user_id).first()
    return render_template('about-us.html', user=user)


@index_blu.route("/cart.html")
def cart():
    user_id = session.get("user_id")
    user = db.session.query(User).filter(User.user_id == user_id).first()
    return render_template('cart.html', user=user)


@index_blu.route("/checkout.html")
def checkout():
    user_id = session.get("user_id")
    user = db.session.query(User).filter(User.user_id == user_id).first()
    return render_template('checkout.html', user=user)


@index_blu.route("/contact-us.html")
def contact():
    user_id = session.get("user_id")
    user = db.session.query(User).filter(User.user_id == user_id).first()
    return render_template('contact-us.html', user=user)


@index_blu.route("/shop.html")
def shop():
    user_id = session.get("user_id")
    user = db.session.query(User).filter(User.user_id == user_id).first()
    return render_template('shop.html', user=user)


@index_blu.route("/shop-detail.html")
def shop_detail():
    user_id = session.get("user_id")
    user = db.session.query(User).filter(User.user_id == user_id).first()
    return render_template('shop-detail.html', user=user)
